import json

import asyncio
from langchain.tools import BaseTool
from typing import Optional
from utils import init_event_loop
from langchain_core.callbacks import CallbackManagerForToolRun
from loguru import logger
from search.operator import ChronExecutor

class ChronRAG(BaseTool):
    """根据用户查询检索数据库并回复相关内容信息"""
    name: str = "news_information"
    description: str = (
        "根据用户查询的任何问题，检索知识图谱数据库，并返回相应的信息"
    )

    def _run(
        self,
        query: str,
        run_manager: Optional[CallbackManagerForToolRun] = None,
    ) -> str:
        """Run the tool."""
        logger.debug(f"called knowledge with query: {query}")

        result = ChronExecutor().retrieve(query)
        logger.debug(f"end of called knowledge {query}: {result}")
        return result
